package Entidades;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class LoginValidate {
    
    private Connection conn;
    private String query;
    private PreparedStatement stmt;
    private ResultSet rs;
    
    public void salverLogin(){
    
    }
    
    public boolean verifyIfExist(String user, String password) throws SQLException{
        
        conn = LinkDB.LinkDB.getConexao();
        query = "SELECT * FROM login WHERE user = ? AND password = ?";
        stmt = conn.prepareStatement(query);
        stmt.setString(1, user);
        stmt.setString(2, password);
        rs = stmt.executeQuery();
        while(rs.next()){
            return true;
        }        
        
        rs.close();
        stmt.close();
        conn.close();
                
        return false;
    }
    
    public int idLogin(String nameLogin) throws SQLException {
        conn = LinkDB.LinkDB.getConexao();
        query = "SELECT idLogin FROM login WHERE user = ?";
        stmt = conn.prepareStatement(query);
        stmt.setString(1, nameLogin);
        rs = stmt.executeQuery();
        if (rs.next()) {
            return Integer.parseInt(rs.getString("idLogin"));
        } else {
            return 0;
        }
    }
    
}
